home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2286 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Newbie question:  Is this code OK?
  5. Date: Fri, 19 Jan 1996 22:11:28 GMT
  6. Organization: Netcom
  7. Message-ID: <31000875.75333568@nntp.ix.netcom.com>
  8. References: <4dmebk$foq@pegasus.interpac.net> <4doajv$ov0$2@mhafn.production.compuserve.com>
  9. NNTP-Posting-Host: ix-dc6-09.ix.netcom.com
  10. X-NETCOM-Date: Fri Jan 19  2:11:27 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. Bill Symmes <71046.623@CompuServe.COM> wrote:
  14.  
  15. > Why not just
  16. >     while (*string)
  17. >            if (isspace(*string++)
  18. >               numwords++;
  19.  
  20. How    many words in       this sentence?
  21.  
  22. Also, there's another problem in your code and others.  Assuming
  23. string is a pointer to char or array of char, isspace(*string++) may
  24. be invalid.  isspace() requires an int argument that is equal to a
  25. value valid for an unsigned char or to EOF.  If char is signed,
  26. *string may be a negative value that is invalid for isspace().  The
  27. test for space should be isspace((unsigned char) *string++).
  28.  
  29.  
  30. Michael M Rubenstein
  31.